package com.sxj.corejava.code14_Lambda表达式;

import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

/**
 * @author 石小俊
 */
public class Test04_断言型接口 {

    public static void main(String[] args) {
        List<String> addresses = Arrays.asList("南京", "北京", "天津", "苏州", "杭州", "常州", "徐州", "泰州", "盐城", "无锡", "连云港");
        // 匿名内部类用法
        testPredicate(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                return s.contains("京");
            }
        }, addresses);
        System.out.println("*************************");
        // Lambda表达式用法
        testPredicate(address -> address.contains("州"), addresses);
    }

    public static void testPredicate(Predicate<String> predicate, List<String> list) {
        for (String s : list) {
            if (predicate.test(s)) {
                // 当断言型接口方法的返回值为true时执行打印操作
                System.out.println(s);
            }
        }
    }

}
